package twitpic.util
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.ByteArray;

	public class JPEGReader
	{
		public function JPEGReader()
		{
		}

		public static function loadImage(url:String):ByteArray {
			var imageBytes:ByteArray = new ByteArray();
			var file:File = new File(url);
			var stream:FileStream = new FileStream();
			stream.open(file, FileMode.READ);
			stream.readBytes(imageBytes);
			stream.close();
			return imageBytes;

			/*
			// security policy disable BitmapData to draw external image
			var imageLoader:Loader = new Loader();
			var bmpData:BitmapData = new BitmapData(500, 500, false);
			var imageBytes:ByteArray;

			imageLoader.load(new URLRequest(url));
			bmpData.draw(imageLoader);
			var jpgObj:JPGEncoder = new JPGEncoder(50);
			imageBytes = jpgObj.encode(bmpData);
			imageBytes.position = 0;
			return imageBytes;
			*/
		}
	}
}